﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Meraz.Core.Model;

namespace Meraz.Core.Repositories
{
    public class LinkRepository : EFRepositoryBase<Link, int>, ILinkRepository
    {
        public LinkRepository() : base() { }
        public LinkRepository(Data.IMerazContext context) : base(context) { }
        public override Link GetById(int id)
        {
            return context.Links
                .Where(where1 => where1.ID == id)
                .FirstOrDefault();
        }

        public Link GetByHref(int postID, string href)
        {
            return context.Links
                .Where(where1 => where1.Post.ID == postID && where1.Url.Name == href)
                .FirstOrDefault();
        }

        public override void Add(Link entity)
        {
            context.Links.AddObject(entity);
        }

        public override void Delete(Link entity)
        {
            context.Links.DeleteObject(entity);
        }

        public override List<Link> All()
        {
            return context.Links.ToList();
        }
    }
}
